//
//  OCTabBar.m
//  ocVB
//
//  Created by apple on 2016/10/23.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "OCTabBar.h"

@interface OCTabBar ()<UITabBarDelegate>

@property(nonatomic,weak)UIButton * btnItem;

@end

@implementation OCTabBar

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
       [self addView];
    }
    return  self;
    
}
#pragma mark -- 搭建界面
- (void)addView
{
    UIButton *btnItem = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnItem setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [btnItem setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    [btnItem setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [btnItem setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    [btnItem sizeToFit];
    self.btnItem = btnItem;
    [self addSubview:btnItem];
    
}

/**
 重新布局子控件
 */
-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat width = self.bounds.size.width * 0.2;
    int idx = 0;
    for (UIView *item in self.subviews) {
        if ([item isKindOfClass:NSClassFromString(@"UITabBarButton")]){
            item.frame = CGRectMake(width * idx, 0, width, self.bounds.size.height);
            idx++;
        }if (idx == 2) {
  
            idx++;
        }
    }

    self.btnItem.frame = CGRectMake(width * 2, 0, width, self.bounds.size.height);
    
    
}


@end
